import pandas as pd

data ={
    "Department": ["HR", "Finance", "HR", "IT", "IT"],
    "Name": ["Sam", "Emma", "Peter", "John", "Lily"],
    "Salary": [7000, 8000, 12000, 15000, 13000],
}
df = pd.DataFrame(data)

# 1.按部门 分组
grouped = df.groupby("Department")

# 2.求部门 平均工资
grouped_Salary_mean = grouped['Salary'].mean()
print(grouped_Salary_mean)
""" 
Department
Finance     8000.0
HR          9500.0
IT         14000.0
Name: Salary, dtype: float64
"""

# 3.求部门 平均工资,工资综合,并命名列名
grouped_Salary_mean_sum = grouped['Salary'].agg(['mean', 'sum'])
print(grouped_Salary_mean_sum)
""" 
               mean    sum
Department
Finance      8000.0   8000
HR           9500.0  19000
IT          14000.0  28000
"""